#!/bin/bash
#SBATCH -o running.out
#SBATCH -o running.err
#SBATCH -p huce_intel
#SBATCH -n 1
#SBATCH --mem 40000
#SBATCH -t 1000

for i in $(seq 1 38); do
iprint=$(printf '%02d' $i)
if [ ! -d ~/holylfs04/cesm_output/ctlnudge$iprint/atm ]; then
CASEROOT=~/cesm_caseroot/ens/ctlnudge$iprint
cd $CASEROOT
caseminus=$(($i-1))
branchname=$(printf '%02d' $caseminus)
BRCPATH="/n/home08/nedkleiner/holylfs04/MERRAfolder/hour0"
BRCCASE="MERRAthreehr$branchname""_0"
BRCDATE="0001-01-16"  #set before
./xmlchange -file env_run.xml -id RUN_TYPE -val "branch"
./xmlchange -file env_run.xml -id RUN_REFCASE -val $BRCCASE
./xmlchange -file env_run.xml -id RUN_REFDATE -val $BRCDATE
./xmlchange -file env_run.xml -id GET_REFCASE -val FALSE
month=1
 ./xmlchange -file env_build.xml -id EXEROOT -val ~/holylfs04/cesm_output/ctlnudge$iprint/bld/
 ./xmlchange -file env_run.xml -id RUNDIR -val ~/holylfs04/cesm_output/ctlnudge$iprint/run/
 ./xmlchange -file env_run.xml -id DOUT_S -val TRUE  #TODO
 ./xmlchange -file env_run.xml -id DOUT_S_ROOT -val ~/holylfs04/cesm_output/ctlnudge$iprint/
cp -a ${BRCPATH}/${BRCCASE}/rest/${BRCDATE}-00000/rpointer.* ~/holylfs04/cesm_output/ctlnudge$iprint/run/
   ln -sf ${BRCPATH}/${BRCCASE}/rest/${BRCDATE}-00000/${BRCCASE}.* ~/holylfs04/cesm_output/ctlnudge$iprint/run/
fi
done
